package com.ruis.kotboot.config.confs

import com.ruis.kotboot.common.filter.RuisXssFilter
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.web.servlet.FilterRegistrationBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import javax.servlet.Filter


@Configuration
@ConditionalOnProperty(prefix = "spring.ruis", name = ["xss"], havingValue = "true")
class RuisXssConfiguration {
    @Bean
    fun ruisFilterRegistrationBean(): FilterRegistrationBean<Filter> {
        val filterRegistrationBean = FilterRegistrationBean<Filter>()
        filterRegistrationBean.filter = RuisXssFilter()
        filterRegistrationBean.addUrlPatterns("/*")
        return filterRegistrationBean
    }
}